<template>
    <el-form ref="form" label-width="80px" size="mini" label-position="left" style="margin: 20px">
        <el-form-item label="品牌名称">
            <el-input v-model="brand.name" placeholder="请输入品牌名称！"></el-input>
        </el-form-item>
        <el-form-item label="选择厂家">
            <el-input v-model="belongname" placeholder="请选择品牌所属厂商！" disabled>
                <el-button slot="append" icon="el-icon-search" @click="selfactory"></el-button>
            </el-input>
        </el-form-item>
        <el-form-item label="品牌描述">
            <el-input type="textarea" v-model="brand.remarks" placeholder="请输入品牌描述！"></el-input>
        </el-form-item>
        <el-form-item label="启用状态" v-show="!brand.id">
            <el-radio class="radio" v-model="brand.radio" label="0">立即启用</el-radio>
            <el-radio class="radio" v-model="brand.radio" label="1">暂不启用</el-radio>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submit">保存</el-button>
            <el-button @click="close">取消</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import C from '#/src/common/common.js'
import Factory from '#/src/shop/factory.js'
import Brand from '#/src/shop/brand.js'

export default {
    name: 'addBrand',
    data() {
        return {
            brand: {
                id: 0,
                name: '',
                remarks: '',
                belongs: 0,
                radio: '0',
            },
            belongname: ''
        }
    },
    methods: {
        selfactory: async function() {
            let res = await Factory.openFactoryList()
            if (res) {
                this.brand.belongs = res.id
                this.belongname = res.name
            }
        },
        async submit() {
            let res = await Brand.addBrand(this.brand)
            if (res) {
                C.closeBrowserWindow(res)
            }
        },
        close() {
            C.closeBrowserWindow()
        }
    },
    mounted: function() {
        let row = C.getDatas()
        if (row && row.id) {
            this.brand.id = row.id
            this.brand.name = row.name
            this.brand.remarks = row.remarks
            this.brand.belongs = row.belongs
            this.belongname = row.fname
            this.brand.isdisabled = row.radio
        }
    }
}
</script>
<style>
</style>